package com.czy.owner.adapter;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.czy.owner.R;
import com.czy.owner.api.BindStoreApi;
import com.czy.owner.db.UserHelper;
import com.czy.owner.entity.GoodsDetailModel;
import com.czy.owner.entity.NearStoreListModel;
import com.czy.owner.global.Constants;
import com.czy.owner.net.http.HttpManager;
import com.czy.owner.net.listener.HttpOnNextListener;
import com.czy.owner.ui.MainActivity;
import com.czy.owner.ui.hotshop.GoodsDetailActivity;
import com.czy.owner.utils.glide.GlideUtils;
import com.czy.owner.widget.UniversalDialog;
import com.easemob.cases.MessageHelper;
import com.easyrecycleview.adapter.BaseViewHolder;
import com.easyrecycleview.adapter.RecyclerArrayAdapter;
import com.hyphenate.EMCallBack;
import com.hyphenate.chat.EMClient;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.util.List;

/**
 * Created by asus on 2017/6/1.
 */

public class NearStoreListAdapter extends RecyclerArrayAdapter<NearStoreListModel> {

    private Context context;
    private BindStoreListener bindStoreListener;

    public NearStoreListAdapter(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {

        return new NearStoreListAdapter.NearStoreListHolder(parent);


    }


    @Override
    public void OnBindViewHolder(BaseViewHolder holder, int position) {
        super.OnBindViewHolder(holder, position);
    }


    class NearStoreListHolder extends BaseViewHolder<NearStoreListModel> {
        private ImageView imgBindStoreHead;
        private TextView tvStoreName;
        private LinearLayout llStoreBind;
        private TextView tvStoreAdrr;
        private TextView tvStoreDistance;

        public NearStoreListHolder(ViewGroup parent) {
            super(parent, R.layout.item_near_store_list_recycler);
            imgBindStoreHead = $(R.id.img_bind_store_head);
            tvStoreName = $(R.id.tv_store_name);
            llStoreBind = $(R.id.ll_bind_store);
            tvStoreAdrr = $(R.id.tv_store_adrr);
            tvStoreDistance = $(R.id.tv_store_distance);
        }

        @Override
        public void setData(final NearStoreListModel model) {
            super.setData(model);
            GlideUtils.loadImage(context, model.getStroeLogo(), imgBindStoreHead, new GlideUtils.ImageLoadListener<String, GlideDrawable>() {
                @Override
                public void onLoadingComplete(String uri, ImageView view, GlideDrawable resource) {

                }

                @Override
                public void onLoadingError(String source, Exception e) {

                }
            }, R.mipmap.store_near_header_bg, R.mipmap.store_near_header_bg);
            tvStoreName.setText(model.getStoreName());
            tvStoreAdrr.setText(model.getStoreLocation());
            if (model.getMin() < 1) {
                tvStoreDistance.setText("距离 " + (int) (model.getMin() * 1000) + "米以内");
            } else {
                tvStoreDistance.setText("距离 " + model.getMin() + "km");
            }
            llStoreBind.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (bindStoreListener != null) {
                        bindStoreListener.onBindClickListener(model.getStoreId());
                    }

                }
            });

        }



    }



    public interface BindStoreListener {
        void onBindClickListener(int storeId);
    }


    public void setBindStoreListener(BindStoreListener bindStoreListener) {
        this.bindStoreListener = bindStoreListener;
    }

}
